<template>
<div>

<home-header ></home-header>
<home-swiper :imglist="imglist"></home-swiper>
<home-icons :iconslist="iconslist"></home-icons>
<home-promotion></home-promotion>
<home-hot :hotGoods="hotGoods"></home-hot>
<home-like :likeGoods="likeGoods"></home-like>
<home-weekend :weekendGoods="weekendGoods"></home-weekend>
<home-footer></home-footer>
</div>
    
    
</template>

<script>
    import HomeHeader from "./components/header";
    import HomeSwiper from './components/swiper';
    import HomeIcons from './components/icons';
    import HomePromotion from './components/promotion';
    import HomeHot  from './components/hot';
    import HomeLike from './components/like';
    import HomeWeekend from './components/weekend';
    import HomeFooter from './components/footer';
    import axios from 'axios'
    import {mapState} from 'vuex'
    export default {
        name:'Home',
        components:{
            HomeHeader,
            HomeSwiper,
            HomeIcons,
            HomePromotion,
            HomeHot,
            HomeLike,
            HomeWeekend,
            HomeFooter
        },
        data(){
return{
lastcity:'', 
imglist:[],
iconslist:[],
hotGoods:[],
likeGoods:[],
weekendGoods:[],



}



        },
        computed:{
          ...mapState(['city'])
        },
        methods: {
    getHomeInfo() {
      axios({
        url:"https://www.easy-mock.com/mock/5b46b28a6c716f5074cd9e04/index?city="+this.city,
        
        methods:'get'
      })

        .then(this.getHomeInfoSucc);
    },
    getHomeInfoSucc(res) {
      res = res.data;
      console.log(res)
      if (res.ret && res.data) {
        const data = res.data;
        
        this.imglist=data.imglist;
        this.iconslist=data.iconslist;
        this.hotGoods=data.hotGoods;
        this.likeGoods=data.likeGoods;
        this.weekendGoods=data.weekendGoods
        
      }
    }
  },
  mounted() {
    this.lastcity=this.city
    this.getHomeInfo();
    
  },
  activated(){
    if(this.lastcity!==this.city){
     this.lastcity=this.city 
     this.getHomeInfo(); 
    
    }
  }
        
    }
</script>

<style  scoped>
 
</style>